/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kurvykurvy.image;

import com.kurvykurvy.ui.dnd.CollageItem;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.swing.TransferHandler;

/**
 *
 * @author HY
 */
public class LoadedImageTransferHandler
        extends TransferHandler
{

    private LoadedImage transferData;
    public static DataFlavor LOADED_IMAGE_FLAVOR;

    static
    {
        try
        {
            LOADED_IMAGE_FLAVOR = new DataFlavor( LoadedImage.MIME_TYPE );
        }
        catch ( ClassNotFoundException e )
        {
            e.printStackTrace();
        }
    }

    public LoadedImageTransferHandler( LoadedImage img )
    {
        this.transferData = img;
    }

    public DataFlavor[] getTransferDataFlavors()
    {
        return new DataFlavor[]
                {
                    LOADED_IMAGE_FLAVOR
                };
    }

    public boolean isDataFlavorSupported( DataFlavor flavor )
    {
        return flavor.isMimeTypeEqual( LOADED_IMAGE_FLAVOR.getMimeType() );
    }

    public Object getTransferData( DataFlavor flavor ) 
            throws UnsupportedFlavorException, IOException
    {
        if ( flavor.equals( LOADED_IMAGE_FLAVOR ) )
        {
            return transferData;
        }
        else
        {
            return new UnsupportedFlavorException( flavor );
        }
    }
}
